home *** CD-ROM | disk | FTP | other *** search
Wrap
property pSprite, pStageBounds, pCentered, pLimited on getBehaviorDescription me return "SPRITE TRACK MOUSE" & RETURN & RETURN & "This behavior will move a sprite so that it is under the cursor. " & "The sprite will appear with its registration point or center under the cursor's hotspot." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Graphic members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Center sprite on cursor" & RETURN & "* Limited to stage area" end on getBehaviorTooltip me return "Makes a sprite move to follow the cursor around the stage so that the center of the sprite is under the cursor." end on beginSprite me mInitialize(me) end on prepareFrame me mUpdate(me) end on mCenter vRect vHalfWidth = vRect.width / 2 vHalfHeight = vRect.height / 2 return point(vRect.left + vHalfWidth, vRect.top + vHalfHeight) end on mCenterOffset vCenter = mCenter(sprite(pSprite).rect) return vCenter - sprite(pSprite).loc end on mCenteredRect vPoint, vRect vWidth = vRect.width vHeight = vRect.height vHalfWidth = vWidth / 2 vHalfHeight = vHeight / 2 vLeft = vPoint.locH - vHalfWidth vTop = vPoint.locV - vHalfHeight return rect(vLeft, vTop, vLeft + vWidth, vTop + vHeight) end on mInitialize me pSprite = me.spriteNum pStageBounds = point((the stage).rect.width, (the stage).rect.height) end on mStageLimit vRect if vRect.left < 0 then vOffsetH = -vRect.left else vOffsetH = min(0, pStageBounds.locH - vRect.right) end if if vRect.top < 0 then vOffsetV = -vRect.top else vOffsetV = min(0, pStageBounds.locV - vRect.bottom) end if return offset(vRect, vOffsetH, vOffsetV) end on mUpdate me if pCentered then vRect = mCenteredRect(the mouseLoc, sprite(pSprite).rect) else vRect = mCenteredRect(the mouseLoc + mCenterOffset(), sprite(pSprite).rect) end if if pLimited then vRect = mStageLimit(vRect) end if sprite(pSprite).rect = vRect end on mSetCentered me, vBool if not (not vBool) = vBool then pCentered = vBool end if end on mSetLimited me, vBool if not (not vBool) = vBool then pLimited = vBool end if end on mToggleCentered me pCentered = not pCentered end on mToggleLimited me pLimited = not pLimited end on isOKToAttach me, aSpriteType, aSpriteNum case aSpriteType of #graphic: return getPos([#quickTimeMedia, #flash, #digitalVideo], sprite(aSpriteNum).member.type) = 0 #script: return 0 end case end on getPropertyDescriptionList vPDList = [:] setaProp(vPDList, #pCentered, [#comment: "Center sprite on cursor (alternative is to use loc)", #format: #boolean, #default: 1]) setaProp(vPDList, #pLimited, [#comment: "Limited to stage area", #format: #boolean, #default: 1]) return vPDList end